function IContainerPurchase(container, item, options) {
  this._container = container;
  this._item = item;
  this._options = options;
  
  this._isPackage = (options && options.isPackage) ? options.isPackage : false;
  
  this._createElements();
};
IContainerPurchase.prototype._createElements = function() {
  var gui, div, table, mtr, mtd, input, select,  unique = MiscUtils.unique();
  DOMUtils.removeChildElements(this._container);
  
  this._container.style.verticalAlign = 'top';
  
  if (this._isPackage) {
    var table = document.createElement('table');
    table.style.backgroundColor = '#eeeeee';
    table.style.padding = '10px 0';
    table.style.width = '773px';
    table.style.height = '10px';
    this._container.appendChild(table);
    
    tr = table.insertRow(-1);  
    td = tr.insertCell(-1);
    td.align = 'right';
    td.style.width = '30px';
    td.style.height = '25px';
    td.style.paddingLeft = '27px';
    td.style.verticalAlign = 'middle';
    td.style.fontWeight = 'bold';
    td.style.color = '#695f55';
    td.style.fontSize = '10pt';
    td.appendChild(document.createTextNode('Product'));
    
    td = tr.insertCell(-1);
    td.align = 'left';
    td.style.verticalAlign = 'middle';
    td.style.width = '300px';
    td.style.color = '#000';
    td.id = unique + '_product_td';
    select = document.createElement('select');
    select.style.width = '300px';
    select.style.height = '21px';
    select.style.borderRight = 'solid 1px #fff';
    select.style.borderBottom = 'solid 1px #fff';
    select.style.borderTop = 'solid 1px #d2c4b9';
    select.style.borderLeft = 'solid 1px #d2c4b9';
    select.style.height = '22px';
    select.id = unique + '_sample_select';
    td.appendChild(select);
    
    td = tr.insertCell(-1);
    td.align = 'right';
    td.style.verticalAlign = 'middle';
    td.style.paddingRight = '10px';
    td.style.width = '30px';
    td.style.fontWeight = 'bold';
    td.style.color = '#695f55';
    td.style.fontSize = '10pt';
    td.appendChild(document.createTextNode('Quantity'));
    
    td = tr.insertCell(-1);
    td.style.width = '40px';
    input = DOMUtils.createInput(null, null, 'text', '', null);
    input.id = unique + '_quantity_text';
    input.style.width = '40px';
    input.style.borderRight = 'solid 1px #fff';
    input.style.borderBottom = 'solid 1px #fff';
    input.style.borderTop = 'solid 1px #d2c4b9';
    input.style.borderLeft = 'solid 1px #d2c4b9';
    input.style.height = '18px';
    input.style.textAlign = 'center';
    td.appendChild(input);
    
    td = tr.insertCell(-1);
    td.align = 'right';
    td.style.verticalAlign = 'middle';
    td.style.width = '40px';
    td.style.paddingRight = '10px';
    td.style.fontWeight = 'bold';
    td.style.color = '#695f55';
    td.style.fontSize = '10pt';
    td.appendChild(document.createTextNode('Price'));
    
    td = tr.insertCell(-1);
    td.align = 'left';
    td.style.verticalAlign = 'middle';
    td.style.width = '50px';
    input = DOMUtils.createInput(null, null, 'text', '', null);
    input.id = unique + '_price_text';
    input.style.width = '50px';
    input.style.borderRight = 'solid 1px #fff';
    input.style.borderBottom = 'solid 1px #fff';
    input.style.borderTop = 'solid 1px #d2c4b9';
    input.style.borderLeft = 'solid 1px #d2c4b9';
    input.style.height = '18px';
    input.style.textAlign = 'center';
    td.appendChild(input);
    
    td = tr.insertCell(-1);
    td.align = 'left';
    td.style.width = '160px';
    td.style.paddingLeft = '3px';
    td.id = unique + '_gst_div';
    
    
    if (this._item.sample) {
      if (this._item.sample.attributes.length == 0) {
        var table1 = document.createElement('table');
        table1.style.backgroundColor = '#eeeeee';
        table1.style.height = '10px';
        this._container.appendChild(table1);
      } else {
        var atable = document.createElement('table');
        atable.style.backgroundColor = '#eeeeee';
        atable.style.borderTop = 'solid 1px #B3B3BA';
        atable.style.borderBottom = 'solid 1px #B3B3BA';
        atable.style.padding = '10px 0';
        atable.style.width = '773px';
        atable.style.height = '10px';
        this._container.appendChild(atable);
        
        tr = atable.insertRow(-1);
        td = tr.insertCell(-1);
        td.style.width = '27px';
        td = tr.insertCell(-1);
        td.align = 'left';
        this._attributeTable = document.createElement('table');
        this._attributeTable.cellPadding = 0;
        this._attributeTable.cellSpacing = 0;
        this._attributeTable.style.width = '720px';
        td.appendChild(this._attributeTable);
        td = tr.insertCell(-1);
        td.style.width = '27px';
    
        while (this._attributeTable.rows.length > 0) {
          this._attributeTable.deleteRow(0);
        }
        var sample = this._item.sample;
        if (sample) {
          for (var i = 0, il = sample.attributes.length; i < il; i++) {
            var attribute = sample.attributes[i];
            atr = this._attributeTable.insertRow(-1);
            atd = atr.insertCell(-1);
            atd.style.width = '720px';
            atd.style.backgroundColor = '#faf9f4';
            atd.style.borderBottom = 'solid 2px #eee';
            atd.style.height = '24px';
            atd.align = 'right';
            var itable = document.createElement('table');
            itable.style.width = '720px';
            itable.cellPadding = 0;
            itable.cellSpacing = 0;
            atd.appendChild(itable);
            
            itr = itable.insertRow(-1);
            itd = itr.insertCell(-1);
            itd.style.width = '60px';
            var span = document.createElement('span');
            span.style.color = '#695f55';
            span.style.fontSize = '14px';
            span.style.fontFamily = '黑体';
            span.style.fontWeight = 'bold';
            span.style.margin = '0 0 0 5px';
            span.id = unique + '_' + i + '_name_div';
            itd.appendChild(span);
      
            for (var j = 0, jl = attribute.options.length; j < jl; j++) {
              var option = attribute.options[j];
              itd = itr.insertCell(-1);
              itd.style.borderLeft = 'dashed 1px #ccc';
              itd.style.height = '24px';
              itd.style.width = '58px';
              itd.style.cursor = 'pointer';
              itd.style.color = '#000000';
              itd.style.fontSize = '13px';
              itd.style.fontFamily = '宋体';
              itd.align = 'center';
              itd.id = unique + '_' + i + '_' + j + '_name_div';
            }
            itd = itr.insertCell(-1);
          }
        }
        
        
        if (this._item.sample.type == '{{$smarty.const.SAMPLE_TYPE_ALBUM|escape:javascript}}' || this._item.sample.type == '{{$smarty.const.SAMPLE_TYPE_MAGAZINE|escape:javascript}}') {
          var tr, td;
          var dtable = document.createElement('table');
          dtable.style.backgroundColor = '#eee';
          dtable.style.width = '773px';
          dtable.style.height = '10px';
          this._container.appendChild(dtable);
          
          tr = dtable.insertRow(-1);
          td = tr.insertCell(-1);
          td.style.width = '27px';
          td = tr.insertCell(-1);
          td.align = 'left';
          this._designTable = document.createElement('table');
          this._designTable.cellPadding = 0;
          this._designTable.cellSpacing = 0;
          this._designTable.style.width = '720px';
          this._designTable.id = unique + '_design_div';
          td.appendChild(this._designTable);
          td = tr.insertCell(-1);
          td.style.width = '27px';
        }
      }
    }
    
    var gui = GuiContainerPurchase.instance(unique, this._item.sample);
    new HandleContainerPurchase(gui, this._item, this._options);
  } else {
    var table = document.createElement('table');
    table.style.backgroundColor = '#eeeeee';
    table.style.padding = '10px 0';
    table.style.width = '773px';
    table.style.height = '10px';
    this._container.appendChild(table);
    
    tr = table.insertRow(-1);  
    td = tr.insertCell(-1);
    td.align = 'right';
    td.style.width = '30px';
    td.style.height = '25px';
    td.style.paddingLeft = '27px';
    td.style.verticalAlign = 'middle';
    td.style.fontWeight = 'bold';
    td.style.color = '#695f55';
    td.style.fontSize = '10pt';
    td.appendChild(document.createTextNode('Product'));
    
    td = tr.insertCell(-1);
    td.align = 'left';
    td.style.verticalAlign = 'middle';
    td.style.width = '300px';
    td.style.color = '#000';
    td.id = unique + '_product_td';
    select = document.createElement('select');
    select.style.width = '300px';
    select.style.height = '21px';
    select.style.borderRight = 'solid 1px #fff';
    select.style.borderBottom = 'solid 1px #fff';
    select.style.borderTop = 'solid 1px #d2c4b9';
    select.style.borderLeft = 'solid 1px #d2c4b9';
    select.style.height = '22px';
    select.id = unique + '_sample_select';
    td.appendChild(select);
    
    td = tr.insertCell(-1);
    td.align = 'right';
    td.style.verticalAlign = 'middle';
    td.style.paddingRight = '10px';
    td.style.width = '30px';
    td.style.fontWeight = 'bold';
    td.style.color = '#695f55';
    td.style.fontSize = '10pt';
    td.appendChild(document.createTextNode('Quantity'));
    
    td = tr.insertCell(-1);
    td.style.width = '40px';
    input = DOMUtils.createInput(null, null, 'text', '', null);
    input.id = unique + '_quantity_text';
    input.style.width = '40px';
    input.style.borderRight = 'solid 1px #fff';
    input.style.borderBottom = 'solid 1px #fff';
    input.style.borderTop = 'solid 1px #d2c4b9';
    input.style.borderLeft = 'solid 1px #d2c4b9';
    input.style.height = '18px';
    input.style.textAlign = 'center';
    td.appendChild(input);
    
    td = tr.insertCell(-1);
    td.align = 'right';
    td.style.verticalAlign = 'middle';
    td.style.width = '40px';
    td.style.paddingRight = '10px';
    td.style.fontWeight = 'bold';
    td.style.color = '#695f55';
    td.style.fontSize = '10pt';
    td.appendChild(document.createTextNode('Price'));
    
    td = tr.insertCell(-1);
    td.align = 'left';
    td.style.verticalAlign = 'middle';
    td.style.width = '50px';
    input = DOMUtils.createInput(null, null, 'text', '', null);
    input.id = unique + '_price_text';
    input.style.width = '50px';
    input.style.borderRight = 'solid 1px #fff';
    input.style.borderBottom = 'solid 1px #fff';
    input.style.borderTop = 'solid 1px #d2c4b9';
    input.style.borderLeft = 'solid 1px #d2c4b9';
    input.style.height = '18px';
    input.style.textAlign = 'center';
    td.appendChild(input);
    
    td = tr.insertCell(-1);
    td.align = 'left';
    td.style.width = '160px';
    td.style.paddingLeft = '3px';
    td.id = unique + '_gst_div';
    
    
    if (this._item) {
      if (this._item.selects.length == 0) {
        var table1 = document.createElement('table');
        table1.style.backgroundColor = '#eeeeee';
        table1.style.height = '10px';
        this._container.appendChild(table1);
      } else {
        var atable = document.createElement('table');
        atable.style.backgroundColor = '#eeeeee';
        atable.style.borderTop = 'solid 1px #B3B3BA';
        atable.style.borderBottom = 'solid 1px #B3B3BA';
        atable.style.padding = '10px 0';
        atable.style.width = '773px';
        atable.style.height = '10px';
        this._container.appendChild(atable);
        
        tr = atable.insertRow(-1);
        td = tr.insertCell(-1);
        td.style.width = '27px';
        td = tr.insertCell(-1);
        td.align = 'left';
        this._attributeTable = document.createElement('table');
        this._attributeTable.cellPadding = 0;
        this._attributeTable.cellSpacing = 0;
        this._attributeTable.style.width = '720px';
        td.appendChild(this._attributeTable);
        td = tr.insertCell(-1);
        td.style.width = '27px';
    
        while (this._attributeTable.rows.length > 0) {
          this._attributeTable.deleteRow(0);
        }
        var sample = DlmanageUtils.sample(this._item, this._options.samples);
        if (sample) {
          for (var i = 0, il = sample.attributes.length; i < il; i++) {
            var attribute = sample.attributes[i];
            atr = this._attributeTable.insertRow(-1);
            atd = atr.insertCell(-1);
            atd.style.width = '720px';
            atd.style.backgroundColor = '#faf9f4';
            atd.style.borderBottom = 'solid 2px #eee';
            atd.style.height = '24px';
            atd.align = 'right';
            var itable = document.createElement('table');
            itable.style.width = '720px';
            itable.cellPadding = 0;
            itable.cellSpacing = 0;
            atd.appendChild(itable);
            
            itr = itable.insertRow(-1);
            itd = itr.insertCell(-1);
            itd.style.width = '60px';
            var span = document.createElement('span');
            span.style.color = '#695f55';
            span.style.fontSize = '14px';
            span.style.fontFamily = '黑体';
            span.style.fontWeight = 'bold';
            span.style.margin = '0 0 0 5px';
            span.id = unique + '_' + i + '_name_div';
            itd.appendChild(span);
      
            for (var j = 0, jl = attribute.options.length; j < jl; j++) {
              var option = attribute.options[j];
              itd = itr.insertCell(-1);
              itd.style.borderLeft = 'dashed 1px #ccc';
              itd.style.height = '24px';
              itd.style.width = '58px';
              itd.style.cursor = 'pointer';
              itd.style.color = '#000000';
              itd.style.fontSize = '13px';
              itd.style.fontFamily = '宋体';
              itd.align = 'center';
              itd.id = unique + '_' + i + '_' + j + '_name_div';
            }
            itd = itr.insertCell(-1);
          }
        } else {
          for (var i = 0, il = this._item.selects.length; i < il; i++) {
            atr = this._attributeTable.insertRow(-1);
            atd = atr.insertCell(-1);
            atd.style.width = '720px';
            atd.style.backgroundColor = '#faf9f4';
            atd.style.borderBottom = 'solid 2px #eee';
            atd.style.height = '24px';
            atd.align = 'right';
            var itable = document.createElement('table');
            itable.style.width = '720px';
            itable.cellPadding = 0;
            itable.cellSpacing = 0;
            atd.appendChild(itable);
            
            itr = itable.insertRow(-1);
            itd = itr.insertCell(-1);
            itd.style.width = '60px';
            var span = document.createElement('span');
            span.style.color = '#695f55';
            span.style.fontSize = '14px';
            span.style.fontFamily = '黑体';
            span.style.fontWeight = 'bold';
            span.style.margin = '0 0 0 5px';
            span.id = unique + '_' + i + '_name_div';
            itd.appendChild(span);
      
            itd = itr.insertCell(-1);
            itd.style.borderLeft = 'dashed 1px #ccc';
            itd.style.height = '24px';
            itd.style.width = '58px';
            itd.style.cursor = 'pointer';
            itd.style.color = '#000000';
            itd.style.fontSize = '13px';
            itd.style.fontFamily = '宋体';
            itd.align = 'center';
            itd.id = unique + '_' + i + '_name1_div';
            itd = itr.insertCell(-1);
          }
        }
        
        if (this._item.type == '{{$smarty.const.SAMPLE_TYPE_ALBUM|escape:javascript}}' || this._item.type == '{{$smarty.const.SAMPLE_TYPE_MAGAZINE|escape:javascript}}') {
          var tr, td;
          var dtable = document.createElement('table');
          dtable.style.backgroundColor = '#eee';
          dtable.style.width = '773px';
          dtable.style.height = '10px';
          this._container.appendChild(dtable);
          
          tr = dtable.insertRow(-1);
          td = tr.insertCell(-1);
          td.style.width = '27px';
          td = tr.insertCell(-1);
          td.align = 'left';
          this._designTable = document.createElement('table');
          this._designTable.cellPadding = 0;
          this._designTable.cellSpacing = 0;
          this._designTable.style.width = '720px';
          this._designTable.id = unique + '_design_div';
          td.appendChild(this._designTable);
          td = tr.insertCell(-1);
          td.style.width = '27px';
        }
      }
    }
    
    var sample = DlmanageUtils.sample(this._item, this._options.samples);
    var gui = GuiContainerPurchase.instance(unique, sample, this._item);
    new HandleContainerPurchase(gui, this._item, this._options);
  }
};
